package com.imooc.dianping.recommand;

import com.imooc.dianping.dao.RecommendMapper;
import com.imooc.dianping.model.Recommend;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Service
public class RecommendService implements Serializable {

    @Autowired
    private RecommendMapper recommendMapper;

    //召回数据，根据userId召回shopIdList
    public List<Integer> recall(Integer userId){
        Recommend recommend = recommendMapper.selectById(userId);
        if (recommend==null){
            recommend = recommendMapper.selectById("99999999");
        }
        String[] shopIdArr = recommend.getRecommend().split(",");
        List<Integer> shopIdList = new ArrayList<>();
        for (int i = 0; i < shopIdArr.length; i++) {
            shopIdList.add(Integer.valueOf(shopIdArr[i]));
        }
        return shopIdList;
    }

}
